import { Pipe, PipeTransform } from '@angular/core';

/**
 * 京东价格计算（差值：c端价格 - 京东价格）
 */
@Pipe({ name: 'productListStatus' })
export class productListStatusPipe implements PipeTransform {
    transform(value: any, exponent?: any): any {
      // shopPriceC - jdPrice
      let diffNum: any;
      let shopPriceC: any = value.shopPriceC;
      let jdPrice: any = value.jdPrice;
      
      diffNum = (parseFloat(shopPriceC) - parseFloat(jdPrice)).toFixed(2)

      // 'price' 返回差值
      if (exponent == 'price') {
        return diffNum || '0';
      }

      // 'color' 返回颜色(大于0红色，小于0绿色)
      if (exponent == 'color') {
        if (diffNum >= 0) {
          return '#f50'
        } else {
          return '#87d068'
        }
      }
    }
}

